package com.lion.zkl.util;

import java.util.ArrayList;

/**
 * 编程大赛
 * 
 * @author Lion_0710
 * 2016-6-20
 * @version 1.0
 */
public class Test {
	/**
	 * 矩阵转置
	 * 
	 * @param inchar
	 * @param n
	 * @param outchar
	 */
	public void matrixTranspose(char[] inchar, int n, char[] outchar) {
		int row = 0;
		if (inchar.length % n != 0) {
			row = inchar.length / n + 1;
		} else {
			row = inchar.length / n;
		}
		char[][] twochar = new char[row][n];
		int index = 0;
		for (int i = 0; i < row; i++) {
			for (int j = 0; j < n; j++) {
				if (index < inchar.length) {
					twochar[i][j] = inchar[index];
					index++;
				} else {
					break;
				}
			}
		}
		for (int m = 0; m < n; m++) {
			for (int k = 0; k < row; k++) {
				System.out.println(twochar[k][m]);
			}
		}
	}

	/**
	 * 出圈问题
	 * 
	 * @param iTotalNum
	 * @param iKey
	 */
	public void outFunc(int iTotalNum, int iKey) {
		if (iTotalNum < 65535) {
			ArrayList num = new ArrayList();
			for (int i = 1; i <= iTotalNum; i++) {
				num.add(i);
			}
			int index = 0;
			for (int j = 0; j < 2000 - 1;) {
				if (index == num.size()) {
					index = 0;
				}
				if ((j + 1) == iKey || (j + 1) % iKey == 0) {
					num.remove(index);
					index--;
				}
				index++;
				if (num.size() == 1) {
					System.out.println(num.get(0));
					break;
				}
				j++;
				if (j == 1999) {
					j = 0;
				}
			}
		}
	}

	/**
	 * 排序算法
	 * 
	 * @param a
	 */
	private void mysort(int[] a) {
		int size = a.length;
		int[] b = new int[size];
		for (int i = 0; i < size; i++) {
			for (int j = 0; j < size; j++) {
				if (a[i] > a[j]) {
					int dd = a[j];
					a[j] = a[i];
					a[i] = dd;
				}
			}
		}
		for (int k = 0; k < size; k++) {
			System.out.println(a[k]);
		}
	}

	/**
	 * 公交寻址
	 * 
	 * @param inchar
	 * @param n
	 * @param outchar
	 */
	public int findStat(char[] inchar, int n, int length) {
		int row = 0;
		if (inchar.length % n != 0) {
			row = inchar.length / n + 1;
		} else {
			row = inchar.length / n;
		}
		char[][] twochar = new char[row][n];
		int index = 0;
		for (int i = 0; i < row; i++) {
			for (int j = 0; j < n; j++) {
				if (index < inchar.length) {
					twochar[i][j] = inchar[index];
					index++;
				} else {
					break;
				}
			}
		}
		for (int m = 0; m < n; m++) {
			for (int k = 0; k < row; k++) {
				System.out.println(twochar[k][m]);
			}
		}
		return 0;
	}

	public static void main(String[] args) {
		Test test = new Test();
		char[] inchar = { '1', '2', '3', '4', '5', '6', '7', '8', '9' };
		test.matrixTranspose(inchar, 3, null);
		// test.outFunc(15, 2);
		// int [] a = {1,3,9,2,6,8,7,4,0,5};
		// test.mysort(a);
	}
}
